package com.springcloud.servicea.controller;

import com.springcloud.servicea.proxy.CglibLogTestProxy;
import com.springcloud.servicea.proxy.JdkLogTestProxy;
import com.springcloud.servicea.service.LogTestService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * service-b 接口
 * @author: linjinp
 * @create: 2019-07-02 14:16
 **/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping(value = "/")
public class ServicebController {

    @Resource
    private LogTestService logTestService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String say() {
        return "hellow world!!!!";
    }

    /**
     * feign 客户端调用
     * @return
     */
    @RequestMapping(value = "/getMsg", method = RequestMethod.GET)
    public String getMsg() {
        return "这里是服务 b";
    }

    /**
     * JDK 动态代理示例
     * @return
     */
    @RequestMapping(value = "/jdkProxy", method = RequestMethod.GET)
    public String jdkProxy() {
        JdkLogTestProxy log = new JdkLogTestProxy();
        // 获取代理对象
        LogTestService service = (LogTestService) log.creatProxyObject(logTestService);
        System.out.println("调用 printBegin");
        service.printBegin();

        System.out.println("调用 printLog");
        service.printLog("打印日志");
        return "hellow world!!!!";
    }

    /**
     * Cglib 动态代理示例
     * @return
     */
    @RequestMapping(value = "/cglibProxy", method = RequestMethod.GET)
    public String cglibProxy() {
        CglibLogTestProxy log = new CglibLogTestProxy();
        // 获取代理对象
        LogTestService service =  (LogTestService) log.getCglibProxy(logTestService);
        System.out.println("调用 printBegin");
        service.printBegin();

        System.out.println("调用 printLog");
        service.printLog("打印日志");
        return "hellow world!!!!";
    }

}
